import 'package:manager/http/entity/entity_factory.dart';

/// current : 1
/// pages : 1
/// records : [{"createTime":1730894103000,"discountPrice":100.00,"goodsId":"1854130369910652930","goodsInventory":20,"goodsName":"青岛大虾","goodsPic":"https://agropal.oss-cn-beijing.aliyuncs.com/image/ea41617507824f69833205f53eb86013.png","goodsPrice":111.85,"goodsSpecs":"4斤/箱","orderNum":2,"packageUnit":"箱","publish":1,"shopName":"海之味"}]
/// size : 20
/// total : 1

class PageModel<T> {
  int? current;
  int? pages;
  List<T> records;
  int? size;
  int? total;

  PageModel({
    this.current,
    this.pages,
    required this.records,
    this.size,
    this.total,
  });

  bool get hasMore => ((current ?? 0) * (size ?? 0) < (total ?? 0));

  factory PageModel.fromJson(dynamic json) {
    return PageModel(
      records: json['records'] != null
          ? (json['records'] as List)
              .map((e) => EntityFactory.convertOBJ<T>(e) as T)
              .toList()
          : [],
      current: json['current'],
      pages: json['pages'],
      size: json['size'],
      total: json['total'],
    );
  }
}


